package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"strings"
)

// 一次性将文件读入内存，以特定符号分割
// Readfile返回字节切片，需要转为string类型才可以通过strings包中的split函数切割
func main() {
	counts := make(map[string]int)
	files := os.Args[1:]
	if len(files) == 0 {
		fmt.Println("filename is need")
	}
	for _, filename := range files {
		data, err := ioutil.ReadFile(filename)
		if err != nil {
			fmt.Fprintf(os.Stderr, "dup3: %v\n", err)
		}
		for _, msg := range strings.Split(string(data), "\n") {
			counts[msg]++
		}
	}
	for msg, line := range counts {
		if line > 1 {
			fmt.Printf("%d\t%s\n", line, msg)
		}
	}
}
